<?php
class ModelCatalogTryonModel extends Model {
    const TYPE_PC_GLASS = 1;

    public $table = 'tryon_model';

	public function findByProductId($product_id)
    {
        $tbl = $this->getTable();

        $sql = "SELECT * FROM $tbl WHERE product_id = '$product_id' ORDER BY `type`, `sort_order`";

        $query = $this->db->query($sql);

        return $query->rows;
	}

    public function findPcGlassesByProductId($product_id)
    {
        $tbl = $this->getTable();
        $type = self::TYPE_PC_GLASS;

        $sql = "SELECT * FROM $tbl WHERE product_id = '$product_id' AND type = '$type' ORDER BY `type`, `sort_order`";

        $query = $this->db->query($sql);

        return $query->rows;
    }

    public function allPcProductIds()
    {
        $tbl = $this->getTable();
        $type_glass = self::TYPE_PC_GLASS;

        $sql = "SELECT product_id FROM $tbl WHERE type = '$type_glass' GROUP BY product_id";

        $query = $this->db->query($sql);

        return $query->rows ? array_column($query->rows, 'product_id') : [];
    }
}
